<?php

namespace App\Http\Controllers;

use App\Models\Follow;
use App\Util\Url;
use Illuminate\Http\Request;
use App\Util\Tool;

class FansController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 获取粉丝列表
     */
    public function fans(Request $request)
    {
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        if (empty($user)) {
            return $this->ResultJson(3, '用户信息不存在', []);
        }
        //获取用户信息
        $list = $user->follows()->with(['user'])->where('type', 1)->simplePaginate(15)->toArray();
        if (!empty($list['data'])) {
            foreach ($list['data'] as $key => $val) {
                $list['data'][$key] = ['name' => $val['user']['name'] ?? '', 'profile' => Url::getHttpHost() . 'upload/' . ($val['user']['image'] ?? '')];
            }
        } else {
            $list = [];
        }
        return $this->ResultJson(1, '成功!', $list);
    }
}
